<%@ page language="java" import="com.qipay.admin.utils.SiteHelper" contentType="text/html;charset=utf-8" %>
<%@ page import="com.qipay.baas.model.Sp" %>
<%@ page import="com.qipay.baas.model.SpApiConfig" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="java.util.List" %>
<%@ page import="com.qipay.scalar.type.ApiTypeEnum" %>
<%@ page import="com.qipay.baas.model.SpConfig" %>
<!doctype html>
<html>
<head>
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <jsp:include page="head.jsp"></jsp:include>
    <link rel="stylesheet" href="<%= request.getAttribute("StaticHost") %>/css/dataTables.bootstrap.min.css">
    <link rel="stylesheet" href="<%= request.getAttribute("StaticHost") %>/css/list.css">
    <script type="text/javascript">
        //document.getElementsByTagName("html")[0].style.width=screen.availWidth/100+"px";
        document.getElementsByTagName("html")[0].style.fontSize=screen.availWidth/200+"px";
    </script>
    <style type="text/css">
        .border{
            border:1px solid red;
        }
    </style>
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <jsp:include page="nav.jsp"></jsp:include>
    <jsp:include page="left.jsp"></jsp:include>
    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <% Sp spInfo = (Sp) request.getAttribute("detail");
            boolean isAdd = String.valueOf(request.getAttribute("isadd")).equals("1");
            //CpInfo cpInfo = (CpInfo)request.getAttribute("detailInfo");
        %>
        <!-- Main content -->
        <section class="content">
            <div class="row">
                <div class="col-xs-12">
                    <div class="box">
                        <div class="box-header">
                            <h3 class="box-title">sp_config配置列表</h3>
                        </div>
                        <div type="button-group">
                                <a
                                   href="${pageContext.request.contextPath}/sp/config/add?spid=<%= spInfo != null ? spInfo.getId() : ""%>">
                                    <button type="button" class="button back-gray" style="font-size: 1rem">添加参数</button></a>
                                <a  href="javascript:window.history.back()">
                                    <button type="button" class="button back-gray" style="font-size: 1rem">返回</button></a>
                        </div>
                        <br>
                        <hr>
                        <!-- /.box-header -->
                        <div class="tableContent">
                            <table width="100%" border="1" cellspacing="0" cellpadding="0">
                                <thead>
                                <tr>
                                    <th width="5%">ID</th>
                                    <th width="5%">SP名称</th>
                                    <th width="5%">KEY</th>
                                    <th width="30%">Value</th>
                                    <th width="10%">操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                <% List<SpConfig> articles = (List<SpConfig>) request.getAttribute("lst");
                                    if (articles != null && articles.size() > 0) {
                                        Iterator<SpConfig> iter = articles.iterator();
                                        SpConfig user = null;
                                        //ApiTypeEnum apiTypeEnum = user.getApiType();
                                        while (iter.hasNext()) {
                                            user = iter.next();
                                %>
                                <tr id="user_<%=user.getId()%>">
                                    <td><%=user.getId()%>
                                    </td>
                                    <td><%=spInfo.getName()%>
                                    </td>
                                    <td><%=user.getKey()%>
                                    </td>
                                    <td>
                                        <%= user.getVal()%>
                                    </td>
                                    <td>
                                       <div class="button-group">
                                        <a name="lnkDelete" pk="<%= user.getId()%>" href="javascript:;">
                                            <button type="button" class="button back-gray" style="font-size: 1rem">删除</button>
                                        </a>
                                        <a href="${pageContext.request.contextPath}/sp/config/<%= user.getId()%>">
                                            <button type="button" class="button back-gray" style="font-size: 1rem">修改</button></a>
                                       </div>
                                    </td>
                                </tr>

                                <%
                                    }
                                } else {
                                %>
                                <tr>
                                    <td colspan="5">no data.</td>
                                </tr>
                                <% }%>
                                </tbody>
                            </table>
                        </div>
                        <!-- /.box-body -->
                    </div>
                    <!-- /.box -->
                </div>
                <!-- /.col -->
            </div>
            <!-- /.row -->
        </section>
        <!-- /.content -->
    </div>
    <!-- /.content-wrapper -->
    <jsp:include page="foot.jsp"></jsp:include>
</div>
<script src="<%= request.getAttribute("StaticHost") %>/js/jquery.dataTables.min.js"></script>
<script src="<%= request.getAttribute("StaticHost") %>/js/dataTables.bootstrap.min.js"></script>
<script src="<%= request.getAttribute("StaticHost") %>/js/jquery.slimscroll.min.js"></script>
<script src="<%= request.getAttribute("StaticHost") %>/js/fastclick.js"></script>
<script src="<%= request.getAttribute("StaticHost") %>/js/adminlte.min.js"></script>
<script>
    $(function () {
        $('#example2').DataTable({
            'paging': true,
            'lengthChange': false,
            'searching': false,
            'ordering': true,
            'info': true,
            'autoWidth': false
        });
        $("[name='lnkDelete']").click(function () {
            var that = $(this);
            var pk = $(this).attr("pk");
            if (confirm("确定删除吗？")) {
                if (pk > 0) {
                    $.ajax({
                        url: "${pageContext.request.contextPath}/ajax?n=delconfigbyid&id=" + pk,
                        type: "GET",
                        async: true,//true异步 false同步
                        context: this,
                        timeout: 10000,
                        success: function (data) {
                            if (data != null && data == "1") {

                                $("#user_" + pk).hide(200);

                            }
                            else {
                                alert("fail:" + data);
                            }
                        },
                        error: function (d, s, b) {
                            alert("失败:" + b);
                        }
                    });
                }
            }
        });
    })
</script>
</body>
</html>

